package org.apache.doris.demo.spring.controller.api;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.doris.demo.spring.controller.UserProfileController;
import org.apache.doris.demo.spring.model.EvenData;
import org.apache.doris.demo.spring.model.UserTag;
import org.apache.doris.demo.spring.service.TagService;
import org.apache.doris.demo.spring.service.UserTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/userProfile/api")
public class UserProfileApiController {
    @Autowired
    private UserTagService userTagService;
    @Autowired
    private TagService tagService;

    @GetMapping("/timeline/{userId}")
    public List<EvenData> timeline(@PathVariable String userId) {
        List<UserTag> userTags = userTagService.list(new QueryWrapper<UserTag>().eq("userid", userId));
//        String[] timelineData = {"2021", "2022", "2023"};
        List<EvenData> eventData = new ArrayList<>();
        eventData.add(new EvenData("2021年售假被处罚", "2021"));
        eventData.add(new EvenData("2022年被刑拘", "2022"));
        eventData.add(new EvenData("2023年被处罚", "2023"));
        return eventData;
    }

    @GetMapping("/tagCloudList")
    public List<Map<String, String>> tagList() {
        Map<String, Set<String>> tagTypeMap = tagService.getTagTypeMap();
        List<Map<String, String>> tagCloudList = new ArrayList<>();
        for (Set<String> userTag : tagTypeMap.values()) {
            userTag.forEach(tag->{
                tagCloudList.add(Collections.singletonMap("name", tag));
            });
        }
        return tagCloudList;
    }

    @GetMapping("/associateList/{userId}")
    public List<EvenData> personInfoList(@PathVariable String userId) {
        List<UserTag> userTags = userTagService.list(new QueryWrapper<UserTag>().eq("userid", userId));
        List<EvenData> personInfoList = new ArrayList<>();
//        车辆3台，案件2个，关联人15个，关联地点13个
            personInfoList.add(new EvenData("car", "车辆3台"));

            personInfoList.add(new EvenData("case","案件2个"));
            personInfoList.add(new EvenData("associate", "关联人15个"));
            personInfoList.add(new EvenData("address", "关联地点13个"));
        return personInfoList;
    }
    @GetMapping("/keywords/{userId}")
    public ArrayList<UserProfileController.Data> personList(@PathVariable String userId) {
        JSONArray jsonArray = new JSONArray();
        Random random = new Random();
        List<UserTag> userTags=userTagService.list();
        ArrayList<UserProfileController.Data> arrayList = new ArrayList<>();
        for (UserTag userTag : userTags) {
            UserProfileController.Data data=new UserProfileController.Data();
            int value = random.nextInt(10000 - 1000 + 1) + 1000;
            data.setName(userTag.getTagName());
            data.setValue( value);
            arrayList.add(data);
        }
        return arrayList;
    }

}